﻿package com.game.view.component
{
    import com.dusk.util.McUtil;
    import com.dusk.util.ResUtil;
    import com.dusk.util.StringUtil;
    import com.game.data.vo.GameGadgetVO;
    import com.game.manager.GameGadgetManager;
    import com.greensock.TweenMax;
    import com.greensock.easing.Quad;
    
    import config.Config;
    
    import flash.display.DisplayObject;
    
    public class IndicateGadget extends ComponentBase
    {
        
        public function IndicateGadget()
        {
            super();
            needDestroyWhenRemove = false;
        }
        
        private var _type:int;
        
        public var value:int;
        
        public function setGadgetType(type:int):void
        {
            _type = type;
            build();
        }
        
        public function build():void
        {
            McUtil.removeAllChildren(this);
            switch (_type)
            {
                case GameGadgetType.BINGO:
                    addChild(GameGadgetManager.getFilterGadget("Bingo", GameGadgetType.getGadgetColor(GameGadgetType.BINGO)));
                    return;
                case GameGadgetType.MISS:
                    addChild(GameGadgetManager.getFilterGadget("MISS", GameGadgetType.getGadgetColor(GameGadgetType.MISS)));
                    return;
            }
            var arr:Array = StringUtil.int2StringArray(value);
            var num:DisplayObject;
            var str:String;
            for (var i:int = 0; i < arr.length; i++)
            {
                str = arr[i];
                switch (_type)
                {
                    case GameGadgetType.COMBO_NUM:
                        num = ResUtil.getNewObj("num" + str);
                        num.x = i * 50;
                        break;
                    default:
                        num = GameGadgetManager.getFilterGadget(str, GameGadgetType.getGadgetColor(_type));
                        num.x = i * 17;
                        break;
                }
                addChild(num);
            }
        }
        
        override protected function onAdded():void
        {
            if (!GameGadgetType.needTween(_type))
            {
                return;
            }
            switch (gc.userData.hurtNumStyle)
            {
                case 0://zxtt
                    TweenMax.to(this, 1, {
                        "y": y - 100,
                        "alpha": 0,
                        "delay": 0,
                        "onComplete": removeFromParent,
                        "ease": Quad.easeOut
                    });
                    break;
                case 1://zm3
                    TweenMax.to(this, 1, {
                        "y": y - 100,
                        "onComplete": removeFromParent
                    });
                    break;
                case 2://zm4
                    scaleY = 4;
                    scaleX = 4;
                    TweenMax.to(this, 0.2, {
                        "scaleX": 1,
                        "scaleY": 1,
                        "ease": Quad.easeOut
                    });
                    TweenMax.to(this, 1, {
                        "y": (y - 100),
                        "alpha": 0,
                        "delay": 0.25,
                        "onComplete": removeFromParent,
                        "ease": Quad.easeOut
                    });
                    break;
                case 3://zm5
                default:
                    scaleY = 1;
                    scaleX = 1;
                    TweenMax.to(this, 0.6, {
                        "x": x - 20 + 20,
                        "y": y - 100 + 40,
                        "alpha": 0.2,
                        "delay": 0.3,
                        "onComplete": removeFromParent,
                        "ease": Quad.easeOut
                    });
                    TweenMax.to(this, 0.2, {
                        "x": x - 20,
                        "y": y - 100,
                        "scaleX": 1.2,
                        "scaleY": 1.2,
                        "ease": Quad.easeOut
                    });
            }
        }
    }
}
